import java.util.ArrayList;
import java.util.List;


public class NeuronLayer {
	
	protected List<Neuron> neurons = new ArrayList<Neuron>();
	protected int type;
	
	public final static int LINEAR = 0;
	public final static int STEP = 1;
	public final static int LOGISTIC = 2;
	public final static int KOHONEN = 3;
	public final static int WIDROW_HOFF = 4;
	public final static int INPUT = 5;
	
	private float a = (float) 0.1;

	public NeuronLayer(Integer neuronsNum, int type, int weightsNum) {
		this.type = type;
		for(int i=0;i<neuronsNum;i++) {
			Neuron neuron;
			if(weightsNum == 0) neuron = new Input(0);
			else {
				switch(type) {
					case LINEAR: neuron = new LinearNeuron(weightsNum);break;
					case STEP: neuron = new StepNeuron(weightsNum);break;
					case LOGISTIC: neuron = new LogisticNeuron(weightsNum);break;
					case KOHONEN: neuron = new KohonenNeuron(weightsNum);break;
					case WIDROW_HOFF: neuron = new WidrowHoffNeuron(weightsNum);break;
					case INPUT: neuron = new Input(0);break;
					default: neuron = new LinearNeuron(weightsNum);break;
				}
			}
			this.neurons.add(neuron);
		}
	}

	public float getA() {
		return a;
	}

	public void setA(float a) {
		this.a = a;
	}
	
	public NeuronLayer() {}
	
	public void addNeuron(Neuron neuron) {
		this.neurons.add(neuron);
	}
	
	public void setThreshold(Float threshold) {
		for(Neuron neuron : this.neurons) {
			neuron.setThreshold(threshold);
		}
	}
	
	public List<Neuron> getNeurons() {
		return this.neurons;
	}
	
	public void learn(NeuronLayer layer) {
	}
	
	public void handleSignal(NeuronLayer layer) {
		//System.out.println("handle signal");
		for(Neuron neuron : this.neurons) {
			neuron.handleSignal(layer);
		}
	}
	
	public static int GetType(String type) {
		if(type.equalsIgnoreCase("L")) return NeuronLayer.LINEAR;
		if(type.equalsIgnoreCase("P")) return NeuronLayer.STEP;
		if(type.equalsIgnoreCase("S")) return NeuronLayer.LOGISTIC;
		if(type.equalsIgnoreCase("K")) return NeuronLayer.KOHONEN;
		if(type.equalsIgnoreCase("W")) return NeuronLayer.WIDROW_HOFF;
		return NeuronLayer.LINEAR;
	}
}
